{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "422caf4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "l = list(range(0,10,2))\n",
    "t = tuple(range(0,10,3))\n",
    "s = set(range(0,20,4))\n",
    "d = dict(zip(l,t))\n",
    "print(l,t,s,d)\n",
    "for idx,val in enumerate(l):\n",
    "    print(idx,val)\n",
    "for i in l:\n",
    "    print(i)\n",
    "for k,v in d.items():\n",
    "    print(k,v)\n",
    "for i in d:\n",
    "    print(i,d[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1621dc52",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "add\n",
      "a + b =  246\n",
      "i + j =  246 None None\n",
      "[1]\n",
      "[0, 1, 2, 3, 4]\n",
      "[0, 1, 4, 9, 16]\n"
     ]
    }
   ],
   "source": [
    "def sum(a,b):      #函数三要素：名称，参数（分为可变和不可变两类），返回值（可以没有）\n",
    "    print(\"add\")\n",
    "    return a+b\n",
    "def sum1(a,b):\n",
    "    print(\"a + b = \",a + b)\n",
    "l = list()\n",
    "i = 12\n",
    "j = 234\n",
    "print(\"i + j = \",sum(i,j), sum1(i,j), l.append(1))\n",
    "print(l)\n",
    "\n",
    "def quadratic(a):\n",
    "    return a**2\n",
    "l = list(range(0,5,1))\n",
    "print(l)\n",
    "for i,val in enumerate(l): #list内元素只能通过坐标值来改变，所以这里要用enumerate函数取值，取到后再用定义的函数进行改变，最后还要返回一个list\n",
    "    l[i] = quadratic(val)\n",
    "print(l)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a26f6bfe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "i = 0\n",
    "while i < 10:\n",
    "    print(i)\n",
    "    i += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6ddf22e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "140705135994672\n",
      "140705135994672\n",
      "140705135994704\n",
      "140705135994672\n",
      "140705135994736\n"
     ]
    }
   ],
   "source": [
    "# 1. 不可变对象：int，float，long，str，tuple等；\n",
    "a = 1\n",
    "b = a\n",
    "print(id(a))\n",
    "#33719592L\n",
    "print(id(b))\n",
    "#33719592L\n",
    "a = 2\n",
    "print(id(a))\n",
    "#33719568L\n",
    "print(id(b))\n",
    "#33719592L\n",
    "b = 3\n",
    "print(id(b))\n",
    "#33719544L"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ece11107",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0: 0, 2: 3, 4: 6, 6: 9}\n",
      "{0: 0.0, 2: 1.5, 4: 3.0, 6: 4.5}\n"
     ]
    }
   ],
   "source": [
    "l = list(range(0,10,2))\n",
    "t = tuple(range(0,10,3))\n",
    "s = set(range(0,20,4))\n",
    "d = dict(zip(l,t))\n",
    "\n",
    "def half(a):\n",
    "    return a/2\n",
    "print(d)\n",
    "for k,v in d.items(): #dict里key不可更改\n",
    "    d[k] = half(v)\n",
    "print(d) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "eae9177b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 2, 4, 6, 8]\n",
      "[0, 4, 8, 12, 16]\n"
     ]
    }
   ],
   "source": [
    "l = list(range(0,10,2))\n",
    "def double(a):\n",
    "    for i,val in enumerate(a): #此处函数没返回值\n",
    "        a[i] = val * 2\n",
    "print(l)\n",
    "double(l)\n",
    "print(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "97f4a331",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0: 0, 2: 3, 4: 6, 6: 9}\n",
      "{0: 0.0, 2: 1.0, 4: 2.0, 6: 3.0}\n"
     ]
    }
   ],
   "source": [
    "l = list(range(0,10,2))\n",
    "t = tuple(range(0,10,3))\n",
    "d = dict(zip(l,t))\n",
    "def triple(a):\n",
    "    for k,v in d.items():\n",
    "        a[k] = v/3\n",
    "print(d)\n",
    "triple(d)\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e85e0b8f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0, 2, 4, 6, 8) 20\n",
      "[0, 2, 4, 6, 8] 20\n"
     ]
    }
   ],
   "source": [
    "l = list(range(0, 10, 2))\n",
    "t = tuple(l)\n",
    "\n",
    "\n",
    "def sum(a):\n",
    "    sum = 0\n",
    "    for i in a:\n",
    "        sum += i\n",
    "    return sum #有返回值所以要有接收\n",
    "\n",
    "\n",
    "total = sum(t) #所以此处有一个something=···，也可以直接print返回值\n",
    "print(t, total) #即print(t,sum(t))\n",
    "total = sum(l)\n",
    "print(l, total)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5962c1a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
